﻿
@{
	Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<form class="layui-form" action="">
	<input type="hidden" name="id" id="id" class="layui-input" />
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">企业属性</label>
			<div class="layui-input-inline layui-input-wrap">
				<select id="enterpriseAttribute" name="enterpriseAttribute">
					<option value="">请选择</option>
					<option value="1">供应商</option>
					<option value="2">客户</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">编码</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="code" name="code" lay-verify="required" placeholder="请输入编码" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item layui-form-text">
		<div class="layui-inline">
			<label class="layui-form-label">属性</label>
			<div class="layui-input-wrap layui-input-inline">
				<select id="attribute" name="attribute">
					<option value="">请选择</option>
					<option value="1">整体计重</option>
					<option value="2">单SKU计重</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">出库计费方式</label>
			<div class="layui-input-wrap layui-input-inline">
				<select id="oBillingMethod" name="oBillingMethod">
					<option value="">请选择</option>
					<option value="按听">按听</option>
					<option value="按提">按提</option>
					<option value="按吨">按吨</option>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">中文全称</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="chineseName" name="chineseName" lay-verify="required" placeholder="请输入中文全称" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">合同号</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="contractNumber" name="contractNumber" lay-verify="required" placeholder="请输入合同号" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">营业执照</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="license" name="license" lay-verify="required" placeholder="请输入营业执照" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">地址</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="address" name="address" lay-verify="required" placeholder="请输入地址" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">负责人</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="head" name="head" lay-verify="required" placeholder="请输入负责人" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">电话</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="phone" name="phone" lay-verify="required" placeholder="请输入电话" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">Email地址</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="emailAddress" name="emailAddress" lay-verify="required" placeholder="请输入Email地址" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">联系人</label>
			<div class="layui-input-wrap layui-input-inline">
				<input type="text" id="contact" name="contact" lay-verify="required" placeholder="请输入联系人" class="layui-input">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">备注</label>
		<div class="layui-input-block">
			<textarea id="remark" name="remark" lay-verify="required" placeholder="请输入备注" class="layui-input"></textarea>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>

<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>

<script>
	function GetByiddatas(){
		  $.ajax({
			  url:'/Puff/GetByClients',
			  type:'get',
			  data:{id:@ViewBag.id},
			  dataType:'json',
			  success:function(res){
				  console.log(res.data)
				  $("#id").val(res.data.id)
				  $("#enterpriseAttribute").val(res.data.enterpriseAttribute)
				  $("#code").val(res.data.code)
				  $("#attribute").val(res.data.attribute)
				  $("#oBillingMethod").val(res.data.oBillingMethod)
				  $("#chineseName").val(res.data.chineseName)
				  $("#contractNumber").val(res.data.contractNumber)
				  $("#license").val(res.data.license)
				  $("#address").val(res.data.address)
				  $("#head").val(res.data.head)
				  $("#phone").val(res.data.phone)
				  $("#emailAddress").val(res.data.emailAddress)
				  $("#contact").val(res.data.contact)
				  $("#remark").val(res.data.remark)
				  layui.form.render("select");
			  }
		  })
	  }

	  GetByiddatas()

	layui.use(['form', 'laydate'], function(){
	  var form = layui.form;
	  var layer = layui.layer;
	  var laydate = layui.laydate;

	  // 提交事件
	  form.on('submit(demo1)', function(data){
		var field = data.field; // 获取表单字段值
		// 此处可执行 Ajax 等操作
		console.log(field)
		$.ajax({
			url:'/Puff/UpdateClientdatas',
		   data:field,
		   type:'post',
		   dataType:'json',
		   success:res=>{
			   if (res > 0) {
				  //layer信息提示
				  layer.alert('修改成功');//下面是关键代码
				  var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				  window.parent.location.reload(); // 刷新父页
				  parent.layer.close(index); //再执行关闭
				  setTimeout(function () { parent.layer.close(index) }, 30000);//延迟s
			   }
			   else {
				  layer.alert("修改失败！");
			   }
		   }
		})
		return false; // 阻止默认 form 跳转
	  });
	});
</script>

